<template>
  <div class="refund-detail">
    <div class="page-header">
      <h2>退款详情</h2>
      <el-button @click="$router.back()">返回</el-button>
    </div>

    <el-card class="detail-card">
      <template #header>
        <div class="card-header">
          <span>退款信息</span>
        </div>
      </template>

      <el-descriptions :column="2" border>
        <el-descriptions-item label="退款编号">{{ refundInfo.refundNo }}</el-descriptions-item>
        <el-descriptions-item label="订单编号">{{ refundInfo.orderNo }}</el-descriptions-item>
        <el-descriptions-item label="退款金额">¥{{ refundInfo.amount }}</el-descriptions-item>
        <el-descriptions-item label="退款状态">
          <el-tag :type="getStatusType(refundInfo.status)">
            {{ getStatusText(refundInfo.status) }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="退款原因">{{ refundInfo.reason }}</el-descriptions-item>
        <el-descriptions-item label="申请时间">{{ formatDateTime(refundInfo.createTime) }}</el-descriptions-item>
        <el-descriptions-item label="处理时间" :span="2">
          {{ refundInfo.updateTime ? formatDateTime(refundInfo.updateTime) : '-' }}
        </el-descriptions-item>
      </el-descriptions>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
import axios from 'axios'

const route = useRoute()
const refundInfo = ref({})

// 获取退款详情
const getRefundInfo = async () => {
  try {
    const refundNo = route.params.refundNo
    const response = await axios.get(`/api/refund/query/${refundNo}`)
    refundInfo.value = response.data
  } catch (error) {
    ElMessage.error('获取退款详情失败')
  }
}

// 获取状态类型
const getStatusType = (status) => {
  const types = {
    0: 'warning',  // 待处理
    1: 'success',  // 已退款
    2: 'danger'    // 已拒绝
  }
  return types[status] || 'info'
}

// 获取状态文本
const getStatusText = (status) => {
  const texts = {
    0: '待处理',
    1: '已退款',
    2: '已拒绝'
  }
  return texts[status] || '未知状态'
}

// 格式化日期时间
const formatDateTime = (dateTime) => {
  if (!dateTime) return '-'
  return new Date(dateTime).toLocaleString()
}

onMounted(() => {
  getRefundInfo()
})
</script>

<style scoped>
.refund-detail {
  padding: 20px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.detail-card {
  max-width: 800px;
  margin: 0 auto;
}

.card-header {
  font-size: 16px;
  font-weight: bold;
}
</style> 